*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Restat/dataverse_files/Data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 



use "$path2/60years", clear
drop if mi(prov)
merge 1:1 prov year using "$path2/fines_use", nogen 
replace fine = 0 if year <= 1979 & fine == . 
replace fine = . if year < 1978

xtset prov year 

egen cid = group(prov)
gen lnpic = ln(pic)
replace lnpic = 0 if lnpic == . & year <= 2000
gen lnmic = ln(mic)
replace lnmic = 0 if lnmic == . & year <= 2000
gen lnuic = ln(uic)
replace lnuic = 0 if lnuic == . & year <= 2000

gen lnpop = ln(pop)
gen lnpop_male = ln(pop)
gen lnpop_female = ln(pop)
gen lnpop_urban = ln(pop_urban)
gen lnpop_rural = ln(pop_rural)

gen lngdp_pc = ln(gdp/pop*10000)
gen lngdp1_pc = ln(gdp_1st/pop)
gen lngdp2_pc = ln(gdp_2nd/pop)
gen lngdp3_pc = ln(gdp_3rd/pop)

gen gdp1_share = gdp_1st/gdp
gen gdp2_share = gdp_2nd/gdp
gen gdp3_share = gdp_3rd/gdp

gen lngov_exp = ln(exp_gen)
 
gen lngov_admin = ln(exp_admin+1)
gen lngov_ag = ln(exp_ag+1)
gen lngov_cul = ln(exp_cul+1)
gen lngov_ss = ln(exp_ss+1)

replace lngov_ss = 0 if lngov_ss==. & year >= 1978
gen lnwage= ln(wage_total/worker_total)
gen lnwage_urban = ln(wage_urban/worker_urban)
gen lnwage_state = ln(wage_state/worker_state)

gen lnteacher_primary = ln(teacher_primary/pop)
gen lnteacher_second = ln(teacher_second/pop)
gen lnteacher_higher = ln(teacher_higher/pop)

gen lnemp = ln(emp+1)
gen lnemp_urban = ln(emp_urban +1)
gen lnemp_rural = ln(emp_rural +1)

gen lndibao = ln(dibao+1)
replace lndibao = 0 if year <= 1990 & lndibao == . 

gen treat = 1 if prov == 11 | prov == 13 | prov == 21 | prov == 31 | prov == 32 | prov == 33 | prov == 35 |prov == 41 | prov == 42 | prov == 43 |prov == 44 | prov == 45| prov == 46| prov == 53| prov == 64 | prov == 65
replace treat = 0 if mi(treat)


gen p_val = . 
local j = 1 

**** Appendix Table A7 ****

cap erase "$path3/econ_con.xls"
cap erase "$path3/econ_con.txt"
xtset prov year 

preserve
gen fine_90 = fine if year == 1990
bys prov: egen fine_i = min(fine_90)
gen fine_05 = fine if year == 2005
bys prov: egen fine_j = min(fine_05)
gen dfine = fine_j - fine_i

foreach y_var of var  lnpop lnpop_urban lnpop_rural birth_rate death_rate  lnemp lnemp_urban lnemp_rural  lnwage lnwage_urban lnwage_state ///
lngdp_pc unem_rate unem_urban  lnpic lnmic lnuic lndibao lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss ///
bed_per10k doc_per10k lnteacher_primary lnteacher_second lnteacher_higher{
gen `y_var'_78 = `y_var' if year == 1978
bys prov: egen ini_`y_var' = mean(`y_var'_78)

}

keep prov cid dfine ini_*
duplicates drop
gen p_val = .
foreach y_var in  lnpop lnpop_urban lnpop_rural birth_rate death_rate  lnemp lnemp_urban lnemp_rural  lnwage lnwage_urban lnwage_state ///
lngdp_pc unem_rate unem_urban  lnpic lnmic lnuic lndibao lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss ///
bed_per10k doc_per10k lnteacher_primary lnteacher_second lnteacher_higher{
cap noi: reghdfe dfine ini_`y_var', noa 
cap noi: testparm ini_`y_var'
cap noi: outreg2 using "$path3/econ_con.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 1
}
restore

foreach y_var of var  lnpop lnpop_urban lnpop_rural birth_rate death_rate  lnemp lnemp_urban lnemp_rural  lnwage lnwage_urban lnwage_state ///
lngdp_pc unem_rate unem_urban  lnpic lnmic lnuic lndibao lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss ///
bed_per10k doc_per10k lnteacher_primary lnteacher_second lnteacher_higher{
reghdfe d.fine d.(`y_var'), a(prov##c.year year) cluster(cid)
testparm d.(`y_var')
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/econ_con.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 2
}


qui:{
foreach y_var of var  lnpop lnpop_urban lnpop_rural birth_rate death_rate  lnemp lnemp_urban lnemp_rural  lnwage lnwage_urban lnwage_state ///
lngdp_pc unem_rate unem_urban  lnpic lnmic lnuic lndibao lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss ///
bed_per10k doc_per10k lnteacher_primary lnteacher_second lnteacher_higher{
gen `y_var'_1p = l1.`y_var'


reghdfe fine `y_var'_1p , a(prov##c.year year) cluster(cid)
testparm `y_var'_1p 
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/econ_con.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 3
}
}

xtset prov year 

foreach y_var in  "lnpop lnpop_urban lnpop_rural" "birth_rate death_rate"  "lnemp lnemp_urban lnemp_rural"  "lnwage lnwage_urban lnwage_state" "lngdp_pc unem_rate unem_urban" ///
  "lnpic lnmic lnuic lndibao" "lngov_exp lngov_admin lngov_ag lngov_cul lngov_ss" ///
"bed_per10k doc_per10k" "lnteacher_primary lnteacher_second lnteacher_higher"{
reghdfe fine l1.(`y_var') , a(prov##c.year year) cluster(cid)
testparm l1.(`y_var')
replace p_val = `r(p)' in `j' 
local ++j 
outreg2 using "$path3/econ_con.xls", adds(F-test, `r(F)',p-val, `r(p)')  // col 4

cap drop `y_var'_1p `y_var'_2p `y_var'_3p
}






